package com.csxy.chy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.chy.entity.BannerQuery;
import com.csxy.chy.entity.CrmBanner;
import com.csxy.chy.mapper.CrmMapper;
import com.csxy.chy.service.CrmService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CrmServiceImpl extends ServiceImpl<CrmMapper, CrmBanner> implements CrmService {
    @Autowired
    private CrmMapper crmMapper;
    @Override
    public void pageQuery(Page<CrmBanner> bannerPage, BannerQuery bannerQuery) {
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        if (bannerQuery != null){
            crmMapper.selectPage(bannerPage,null);
        }
        if (bannerQuery.getName() != null && !"".equals(bannerQuery.getName())){
            wrapper.like("title",bannerQuery.getName());
        }
        if (!StringUtils.isEmpty(bannerQuery.getBegin())){
            wrapper.ge("gmt_create",bannerQuery.getBegin());
        }
        if (!StringUtils.isEmpty(bannerQuery.getEnd())){
            wrapper.le("gmt_modified",bannerQuery.getEnd());
        }
        crmMapper.selectPage(bannerPage,wrapper);
    }

    @Override
    @Cacheable(value = "banner",key = "'getAllBanner'")
    public List<CrmBanner> getAllBanner() {
        List<CrmBanner> list = baseMapper.selectList(null);
        return list();
    }
}
